package com.telit.android.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.android.dao.AppTaskTypeDao;
import com.telit.android.dto.AppHotportTypeDto;
import com.telit.android.entity.AppTaskType;
import com.telit.android.service.IAppTaskTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 任务类型 服务实现类
 * </p>
 *
 * @author yummy
 * @since 2021-07-22
 */
@Service
@Transactional
public class AppTaskTypeServiceImpl extends ServiceImpl<AppTaskTypeDao, AppTaskType> implements IAppTaskTypeService {

    @Override
    public int add(AppTaskType appTaskType){
        return baseMapper.insert(appTaskType);
    }

    @Override
    public int delete(Integer id){
        return baseMapper.deleteById(id);
    }

    @Override
    public List<Integer> deleteBatch(Integer[] ids){
        List<Integer> values=new ArrayList<Integer>();
        if(ids!=null && ids.length>0){
            for(Integer id:ids){
            values.add(delete(id));
            }
        }
        return values;
    }

    @Override
    public int updateData(AppTaskType appTaskType){
        return baseMapper.updateById(appTaskType);
    }

    @Override
    public AppTaskType findById(Integer id){
        return  baseMapper.selectById(id);
    }

    @Override
    public List<AppHotportTypeDto> findHotport() {
        return baseMapper.findHotport();
    }


    @Override
    public IPage<AppTaskType> findListByPage(AppTaskType appTaskType, Integer page, Integer pageCount){
        IPage<AppTaskType> appTaskTypePage = new Page<>(page, pageCount);
        QueryWrapper<AppTaskType> wrapper=new QueryWrapper<>();
        if(appTaskType !=null){
                if(StringUtils.hasText(appTaskType.getName())){
                wrapper.eq("name",appTaskType.getName());
                }
                if(StringUtils.hasText(appTaskType.getValue())){
                wrapper.eq("value",appTaskType.getValue());
                }
                if(StringUtils.hasText(appTaskType.getParentValue())){
                wrapper.eq("parent_value",appTaskType.getParentValue());
                }
        }
        return   baseMapper.selectPage(appTaskTypePage, wrapper);
    }

    @Override
    public  List<AppTaskType> searchNoPage(AppTaskType appTaskType){
        QueryWrapper<AppTaskType> wrapper=new QueryWrapper<>();
        if(appTaskType !=null){
                if(StringUtils.hasText(appTaskType.getName())){
                wrapper.eq("name",appTaskType.getName());
                }
                if(StringUtils.hasText(appTaskType.getValue())){
                wrapper.eq("value",appTaskType.getValue());
                }
                if(StringUtils.hasText(appTaskType.getParentValue())){
                wrapper.eq("parent_value",appTaskType.getParentValue());
                }
        }
        return   baseMapper.selectList(wrapper);
    }
}
